﻿using Kingdee.BOS;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Enums;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RK.FormPlugin.XHX
{
    [Description("【表单插件】表体双击事件"), HotUpdate]
    public class DzEntityRowDoubleClick : AbstractDynamicFormPlugIn
    {
        public override void EntityRowDoubleClick(EntityRowClickEventArgs e)
        {
            base.EntityRowDoubleClick(e);
            if (e.ColKey == "F_SIBILLNO" || e.ColKey == "F_SOURCEBILLNO")
            {
                ListShowParameter form = new ListShowParameter();
                form.IsLookUp = true;
                //显示全部列
                form.ListType = Convert.ToInt32(BOSEnums.Enu_ListType.List);
                //批次派工单主计划查找动态表单ID
                form.FormId = "SAL_SaleOrder";
                form.MultiSelect = false;
                this.View.ShowForm(form, delegate (FormResult result)
                {
                    ListSelectedRowCollection returnData = (ListSelectedRowCollection)result.ReturnData;
                    //如果不是空值,说明有返回值
                    if (returnData != null)
                    {
                        //FormMetadata engBomBillView = MetaDataServiceHelper.GetFormMetaData(this.Context, "k9e21fe62be294fca91eac62686ffb28e");
                        //BaseDataField field = engBomBillView.BusinessInfo.GetField("FSIMaterialId") as BaseDataField;
                        DynamicObjectDataRow datarow = (DynamicObjectDataRow)returnData[0].DataRow;
                        //DynamicObject entity = (this.View.Model.DataObject["FEntity"] as DynamicObjectCollection)[e.Row];
                        //field.RefIDDynamicProperty.SetValue(entity, datarow.DynamicObject["FMaterialId_Id"]);
                        //field.DynamicProperty.SetValue(entity, datarow.DynamicObject["FMaterialId_ref"]);
                        //DynamicObject MaterialChild = datarow.DynamicObject["FMaterialId_Id"] as DynamicObject;
                        if (e.ColKey == "F_SOURCEBILLNO")
                        {
                            this.View.Model.SetItemValueByID("FMATERIALID", datarow.DynamicObject["FMaterialId_Id"], e.Row);
                            //this.View.Model.SetItemValueByID("F_SOURCEBILLNO", datarow.DynamicObject["FMaterialId_Id"], e.Row);
                            this.View.Model.SetValue("F_SOURCEBILLNO", datarow.DynamicObject["FBillNo"].ToString(), e.Row);
                            this.View.Model.SetValue("F_BILLNOTYPE", datarow.DynamicObject["F_SOType"], e.Row);
                            this.View.Model.SetValue("F_SSALECODE", datarow.DynamicObject["F_Barcode"].ToString(), e.Row);
                            this.View.Model.SetValue("F_SPEC", datarow.DynamicObject["F_spec"].ToString(), e.Row);
                            DynamicObject dot = datarow.DynamicObject["FCUSTID_Ref"] as DynamicObject;
                            this.View.Model.SetValue("F_CUSTOMERNAME", dot["Name"].ToString().Replace("\\2052\\", ""), e.Row);
                            this.View.Model.SetValue("F_BILLNODATE", datarow.DynamicObject["FDate"], e.Row);
                            //this.View.Model.SetValue("F_SIAmount", datarow.DynamicObject["FAmount"], e.Row);
                            this.View.Model.SetValue("FQTY", datarow.DynamicObject["FPriceUnitQty"], e.Row);
                            //this.View.Model.SetValue("F_SIbaseQty", datarow.DynamicObject["FQty"].ToString(), e.Row);
                            this.View.Model.SetItemValueByID("FBASEUNITID", datarow.DynamicObject["FBaseUnitId_Id"], e.Row);
                            this.View.Model.SetItemValueByID("F_SISaleUnit", datarow.DynamicObject["FPriceUnitId_Id"], e.Row);
                        }
                        else
                        {
                            this.View.Model.SetItemValueByID("F_SIMaterialId", datarow.DynamicObject["FMaterialId_Id"], e.Row);
                            this.View.Model.SetValue("F_SIBillNo", datarow.DynamicObject["FBillNo"].ToString(), e.Row);
                            this.View.Model.SetValue("F_SISaleCode", datarow.DynamicObject["F_Barcode"].ToString(), e.Row);
                            this.View.Model.SetValue("F_SISpec", datarow.DynamicObject["F_spec"].ToString(), e.Row);
                            this.View.Model.SetValue("F_SIDATE", datarow.DynamicObject["FDate"], e.Row);
                            this.View.Model.SetValue("F_SIAmount", datarow.DynamicObject["FAmount"], e.Row);
                            this.View.Model.SetValue("F_SIQty", datarow.DynamicObject["FPriceUnitQty"], e.Row);
                            this.View.Model.SetValue("F_SIbaseQty", datarow.DynamicObject["FQty"].ToString(), e.Row);
                            this.View.Model.SetItemValueByID("F_SIBaseUnit", datarow.DynamicObject["FBaseUnitId_Id"], e.Row);
                            this.View.Model.SetItemValueByID("F_SISaleUnit", datarow.DynamicObject["FPriceUnitId_Id"], e.Row);
                        }

                    }
                });
            }
        }
    }
}
